package org.domain.projeto.session;

import org.domain.projeto.dao.UsuarioDAOImpl;
import org.domain.projeto.entity.Usuario;
import org.domain.projeto.service.ProdutoService;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.log.Log;
import org.jboss.seam.security.Credentials;
import org.jboss.seam.security.Identity;

@Name("authenticator")
public class Authenticator
{
    @Logger private Log log;
    @In ProdutoService produtoService;
    @In UsuarioDAOImpl usuarioDAO;
    @In Identity identity;
    @In Credentials credentials;

    public boolean authenticate()
    {
        log.info("authenticating {0}", credentials.getUsername());
        
        Usuario u = new Usuario();
        
        produtoService.teste();
        
        u.setNome("asdfasdf");
        u.setIdusuario(1);
        usuarioDAO.inserir(u);
        
        if ("admin".equals(credentials.getUsername()))
        {
            identity.addRole("admin");
            return true;
        }
        return false;
    }

}
